﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HotelManager.Data_Transfer_Layer;
using HotelManager.Business_Logic_Layer;

namespace HotelManager
{
    public partial class ThemDichVu : Form
    {
        dichvuBLO dv_blo;
        loaidichvuBLO ldv_blo;

        public ThemDichVu()
        {
            InitializeComponent();
            dv_blo = new dichvuBLO();
            ldv_blo = new loaidichvuBLO();
            Load_Data();
        }
        public void Load_Data()
        {
            cbbLoai.DataSource = ldv_blo.get_arr();
        }

        private void bttThem_Click(object sender, EventArgs e)
        {
            if (txtGiaban.Text.Length == 0 || txtSoLuong.Text.Length == 0 || txtTenDV.Text.Length == 0||cbbDonvi.Text==""||cbbLoai.Text=="")
            {
                MessageBox.Show("Vui lòng nhập thông tin đầy đủ", "Lỗi");
                return;
            }
            DialogResult result = MessageBox.Show("Bạn có muốn tạo " + txtTenDV.Text + "?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                string dv_tendv = txtTenDV.Text, dv_donvi = cbbDonvi.Text, ldv_tenloaidv = cbbLoai.Text;
                int dv_soluong = int.Parse(txtSoLuong.Text), dv_gia = int.Parse(txtGiaban.Text);
                int ldv_id = ldv_blo.View_id(ldv_tenloaidv);
                dichvuDTO obj = new dichvuDTO();
                obj.Dv_donvi = dv_donvi;
                obj.Dv_gia = dv_gia;
                obj.Dv_soluong = dv_soluong;
                obj.Dv_tendv = dv_tendv;
                obj.Ldv_id = ldv_id;
                dv_blo.Insert(obj);
                MessageBox.Show("Tạo thành công");
                this.Close();
                QuanLyDichVu frm_qldv = new QuanLyDichVu();
                frm_qldv.truyendulieu();
            }
            else
            {
                MessageBox.Show("Ban chon no");
            }

        }

        private void txtSoLuong_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtSoLuong_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void txtGiaban_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }
    }
}
